//
//  SYTuDiTingKeXinXiView.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/4/24.
//  Copyright © 2019年 SanYi. All rights reserved.
//

#import "SYTuDiTingKeXinXiView.h"
#import "SYTuDiHeaderView.h"
#import "SYAttendLectureTableViewCell.h"
#import "SYXinDeView.h"
#import "SYBackTopView.h"


@interface SYTuDiTingKeXinXiView () <UITableViewDelegate,UITableViewDataSource,SYAttendLectureTableDelegate>
@property (strong, nonatomic) UITableView *curTableView;// 表
@property (strong, nonatomic) SYXinDeView *xindeView;//学习心得
@property (strong, nonatomic) SYBackTopView *backView;//顶部viwe

@end


@implementation SYTuDiTingKeXinXiView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithHexString:@"#EEEEEE"];
        [self initSubView];
    }
    return self;
}
- (void)initSubView {
    [self addSubview:self.backView];
    [self.backView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.height.mas_equalTo(50);
    }];
    //表
    [self addSubview:self.curTableView];
    [self.curTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.backView.mas_bottom).offset(0);
        make.left.equalTo(self).offset(14);
        make.right.equalTo(self.mas_right).offset(-14);
        make.bottom.equalTo(self.mas_bottom).offset(-14);
    }];
}

#pragma mark - tab
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 40;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 223+40;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SYAttendLectureTableViewCell *attendCell = [tableView dequeueReusableCellWithIdentifier:@"SYAttendLectureTableViewCell" forIndexPath:indexPath];
    attendCell.selectionStyle = UITableViewCellSelectionStyleNone;
    attendCell.delegate = self;
    
    [attendCell attendLectureTableViewCellIndexPath:indexPath stusa:0];
    
    return attendCell;
    
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [UIView new];
    SYTuDiHeaderView *tdView = [[SYTuDiHeaderView alloc] init];
    tdView.backgroundColor = [UIColor whiteColor];
    [view addSubview:tdView];
    [tdView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.equalTo(view);
    }];
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [UIView new];
    UIView *topView = [UIView new];
    topView.backgroundColor = [UIColor colorWithHexString:@"F8F8F8"];
    [view addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view);
        make.left.equalTo(view.mas_left).offset(14);
        make.right.equalTo(view.mas_right).offset(-14);
        make.height.mas_equalTo(20);
    }];
    UIView *fgxView = [UIView new];
    fgxView.backgroundColor = [UIColor colorWithHexString:@"#CCCCCC"];
    [view addSubview:fgxView];
    [fgxView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view.mas_top).offset(0);
        make.left.equalTo(view.mas_left).offset(28);
        make.right.equalTo(view.mas_right).offset(-28);
        make.height.mas_equalTo(1);
    }];
    return view;
}
#pragma mark - SYAttendLectureTableDelegate
//听课信息
- (void)attendLectureTableType:(SYDetailsType)type {
    _xindeView = [[SYXinDeView alloc] initWithFrame:CGRectMake(kScreen_WIDTH, 0, CGRectGetWidth(self.frame), kScreen_HEIGHT-20) detailsType:type xindeViewType:SYXinDeViewTypeShiFu];
    [self addSubview:_xindeView];
    __weak typeof(self) weakSelf = self;
    [UIView animateWithDuration:kAnimate animations:^{
        weakSelf.xindeView.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), kScreen_HEIGHT-20);
    }];
}
//头部
- (SYBackTopView *)backView {
    if (!_backView) {
        _backView = [[SYBackTopView alloc] initWithTitleName:@"师训" baseView:self];
    }
    return _backView;
}
- (UITableView *)curTableView {
    if (!_curTableView) {
        _curTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStyleGrouped];
        
        _curTableView.delegate = self;
        _curTableView.dataSource = self;
        _curTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _curTableView.backgroundColor = [UIColor whiteColor];
//        [_curTableView registerCellWithClassNames:@[@"SYAttendLectureTableViewCell"]];
        [_curTableView registerCellWithNIbNames:@[@"SYAttendLectureTableViewCell"]];
    }
    return _curTableView;
}

@end
